package com.BinarySearch;

public class Base {

    /**
     * 二分查找基础练习
     *
     * @param arr
     * @param x
     * @return
     */
    public static int binarySearch(int[] arr, int target) {
        int i = 0;
        int j = arr.length - 1;
        while (i <= j) {
            int currentIndex=(i+j)>>>1;
            if (arr[currentIndex]==target) {
                return currentIndex;
            }
            if (arr[currentIndex]>target) {
               j=currentIndex-1;
            }
            if (arr[currentIndex]<target) {
                i=currentIndex+1;
            }
        }
        return -1;
    }
}

